package com.scujcc.diandiantv;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class ChannelRvAdapter extends RecyclerView.Adapter<ChannelRvAdapter.ChannelRowHolder> {
    @NonNull
    @Override
    public ChannelRowHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.channel_rv, parent, false);
        ChannelRowHolder row = new ChannelRowHolder(view);
        return row;
    }

    @Override
    public void onBindViewHolder(@NonNull ChannelRowHolder holder, int position) {
        Channel c = ChannelLab.get().getChannel(position);
        holder.bind(c);
    }

    @Override
    public int getItemCount() {
        return ChannelLab.get().getChannelCount();
    }

    public class ChannelRowHolder extends RecyclerView.ViewHolder {
        private TextView title;
        private TextView resolution;

        public ChannelRowHolder(@NonNull View row) {
            super(row);
            this.title = row.findViewById(R.id.channel_title);
            this.resolution = row.findViewById(R.id.res);
        }

        public void bind(Channel c) {
            this.title.setText(c.getName());
//            this.resolution.setText(c.getResolution());
        }
    }
}
